import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

/* Layout */
import Layout from '@/layout'
import Test from '@/views/test.vue'

/**
 * 子菜单只能出现在二级路由下
 * 
 * hidden: true                   将会在菜单中隐藏 默认false
 * alawaysShow: true              将会在左侧菜单栏中显示 默认false
 * redirect: noRedirect           当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name: 'router-name'            路由名称 
 * meta : {
    roles: ['admin','editor']    设置该路由进入的权限，支持多个权限叠加
    title: 'title'               设置该路由在侧边栏和面包屑中展示的名字
    icon: 'el-icon-x'            设置该路由的图标，支持 el-icon-x element-ui 的 icon
    noCache: true                如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    affix: true                  设置为true, 标签会被固定在标签窗口中(默认为false)
    breadcrumb: false            如果设置为false，则不会在breadcrumb面包屑中显示(默认 true)
    activeMenu: '/example/list'  当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */
export const constantRoutes = [
  {
    path: '/redirct',
    hidden: true,
    component: Layout,
    children: [
      {
        path: '/redirct/:path(.*)',
        component: Test
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        component: Test,
        name: 'Home',
        meta: { title: '首页', icon: 'house', affix: true }
      }
    ]
  }
]

export const asyncRoutes = [
  {
    path: '/permission',
    component: Layout,
    alwaysShow: true,
    name: 'Permission',
    meta: {
      title: '权限管理',
      icon: 'lock',
      roles: ['admin', 'editor']
    },
    redirect: '/permission/page',
    children: [
      {
        path: 'page',
        component: Test,
        name: 'PagePermission',
        meta: {
          title: '页面管理',
          roles: ['admin']
        }
      },
      {
        path: 'directive',
        component: Test,
        name: 'DirectivePermission',
        meta: {
          title: '指令管理',
          roles: ['admin']
        }
      }
    ]
  },
  {
    path: '/chart',
    redirect: '/chart',
    component: Layout,
    children: [
      {
        path: '/chart',
        name: 'chart-line',
        meta: {
          title: '图表展示',
          icon: 's-marketing'
        },
        component: resolve => require(['@/views/chart.vue'], resolve)
      }
    ]
  }
]

export const routes = constantRoutes.concat(asyncRoutes)

const router = new VueRouter({
  scrollBehavior: () => ({ y: 0 }),
  routes
})

export default router
